<?php

namespace App\Models;


use App\Utils\DateTrait;
use Eloquent;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Tymon\JWTAuth\Contracts\JWTSubject;

/**
 * Class User 用户基础信息
 *
 * @package App\Models
 * @mixin Eloquent
 *
 * @property $user_id
 * @property $is_admin
 */
class User extends Authenticatable implements JWTSubject
{
    use Notifiable, DateTrait, SoftDeletes;

    // 数据表名
    protected $table = 'users';

    // 数据主键
    protected $primaryKey = 'user_id';

    // 隐藏字段
    protected $hidden = ['group_id','deleted_at', 'updated_at'];

    // 批量赋值
    protected $fillable = [];

    // 自动维护时间字段
    public $timestamps = true;

    /**
     * @return mixed
     */
    public function getJWTIdentifier()
    {
        // TODO: Implement getJWTIdentifier() method.
        return $this->getKey();
    }

    /**
     * @return array
     */
    public function getJWTCustomClaims()
    {
        // TODO: Implement getJWTCustomClaims() method.
        return [];
    }

    /**
     * 用户分组（一对一关系）
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function group() {
        return $this->hasOne('App\Models\Group', 'group_id', 'group_id');
    }

    /**
     * 用户密钥（一对多关系）
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function secret() {
        return $this->hasMany('App\Models\UserSecret', 'user_id', 'user_id');
    }

    /**
     * 额外信息（一对一关系）
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function extra() {
        return $this->hasOne('App\Models\UserExtra', 'user_id', 'user_id');
    }
}
